package com.baike.service.impl;

import com.baike.data.Result;
import com.baike.em.ConstantEnum;
import com.baike.entity.TbTeacher;
import com.baike.mapper.TbTeacherMapper;
import com.baike.service.ITbTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2021-10-28
 */
@Service
public class TbTeacherServiceImpl extends ServiceImpl<TbTeacherMapper, TbTeacher> implements ITbTeacherService {
    @Autowired
    private TbTeacherMapper tbTeacherMapper;


    @Override
    public List<TbTeacher> selectByName(String teacherName) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if(teacherName != null && !"".equals(teacherName)){
            queryWrapper.like("TEACHERNAME",teacherName);
        }
        List list = tbTeacherMapper.selectList(queryWrapper);
        return list;
    }
    //通过账号名称查询数据库是否存在
    @Override
    public TbTeacher selectByUserName(String username) {
        TbTeacher teacher = tbTeacherMapper.selectByUserName(username);
        if (teacher == null){
            //当前账号不存在
            return null;
        }

        return teacher;
    }

    //修改教师账号密码
    @Override
    public void toUpdatePassword(String teacherName, String pwd, String salt) {
        tbTeacherMapper.toUpdatePassword(teacherName,pwd,salt);
    }
}
